package gamedsl.acceleo.main;

import gamedsl.acceleo.files.AbstractEntity;
import gamedsl2.Gamedsl2Package;
import org.eclipse.emf.ecore.resource.*;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;

import java.util.ArrayList;
import java.util.List;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;

import org.eclipse.emf.common.util.BasicMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String PATH = "gamedsl.acceleo.files";
		String mainMethod = "main";
		//Debug only
		String[] argb = {"./../GameDSL2/model/M2M-gameDSL-output.xmi",
						"./../alienGameOutput/src"
						};
		try{			
			File sourceDir = new File("./src/gamedsl/acceleo/files");
			
			//Filter all java files
			FilenameFilter filter = new FilenameFilter(){
				public boolean accept(File dir, String name){
					if(name.endsWith(".java")){
						return true;
					}
					return false;
				}
			};
			String[] sourceJavaFiles = sourceDir.list(filter);
			for(int i = 0; i < sourceJavaFiles.length; i++){
				String jFile = sourceJavaFiles[i].substring(0, sourceJavaFiles[i].length()-5);
				System.out.println(jFile);
				Class c = Class.forName(PATH + "." + jFile);
				Method m = c.getMethod(mainMethod,String[].class);
				m.invoke(null,(Object)argb);
				System.out.println(jFile + " Done");
			}
        }catch(InvocationTargetException e){
        	System.err.println(e);
        }
		catch (Throwable e) {
                System.err.println(e);
         }
	}

}
